package msu.erdc.hci;

import msu.erdc.hci.customObjects.InsuranceObject;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;

public class Insurance extends Fragment {
	
	EditText companyName;
	EditText policyNumber;
	EditText contact;
	EditText phoneNumber;
	InsuranceObject policy;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
	{
		View view =  inflater.inflate(R.layout.insurance, container, false);
		//do ui stuff here
		
		companyName = (EditText) view.findViewById(R.id.companyText);
		companyName.setText(policy.companyName);
		
		policyNumber = (EditText) view.findViewById(R.id.policyText);
		policyNumber.setText(policy.policyNum);
		
		contact = (EditText) view.findViewById(R.id.contactText);
		contact.setText(policy.contact);
		
		phoneNumber = (EditText) view.findViewById(R.id.phoneText);
		phoneNumber.setText(policy.phoneNumber);			
		
        return view;
	}
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //TODO
        //if not passed in
        Bundle arguments = getArguments();
        if(!arguments.containsKey("insuranceIndex"))
        	policy = new InsuranceObject();
        else
        	policy = ((Global)getActivity().getApplication()).insurances.get(arguments.getInt("insuranceIndex"));		
	}
	
	@Override
	public void onDestroy()
	{
		policy.companyName = companyName.getEditableText().toString();
		policy.policyNum = policyNumber.getEditableText().toString();
		policy.contact = contact.getEditableText().toString();
		policy.phoneNumber = phoneNumber.getEditableText().toString();
		super.onDestroy();
	}	
}

